home *** CD-ROM | disk | FTP | other *** search
- #include "QD3DtoQTVR.h"
- #include "extern.h"
- #include "camera.h"
- #include "draw.h"
- #include "Panorama.h"
- #include "file.h"
- #include "AEVT.h"
- #include "MyMovies.h"
- #include "document.h"
-
- #define factor 32.0
-
- void MyConvert3DMFToPano(FSSpec *myFSS)
- {
- DocumentPtr theDocument;
-
- // Create the document record and make the view and camera
- theDocument = MyNewDocument();
- if (!theDocument)
- return;
-
- // Read the model and add it to the document record's group
- if(MyOpenFile(myFSS, theDocument)) {
- MyCloseDocument(theDocument);
- return;
- }
-
- // Set up the initial camera position for object rendering
- MyInitPanoCamera(theDocument);
-
- // Draw to the screen
- MyDrawOffScreen(theDocument);
- MyDrawOnScreen(theDocument);
-
- // Assign the Codec type
- theDocument->theCodecType = kMyCodec;
-
- // generate the pano image
- MyGeneratePanoDirect(theDocument);
-
- // Clean up
- MyCloseDocument(theDocument);
- }
-
- void MyGeneratePanoDirect(DocumentPtr theDocument)
- {
- PicHandle thePict;
- float zAngle;
- long counter = 0;
- Str255 fName = "\p.pan";
- short i;
- GWorldPtr gw,largeGW;
- GDHandle gd;
- FSSpec outSpec;
- Rect sourceRect,destRect,largeRect = {0, 0, 768, 2496};
- OSErr err;
-
- GetGWorld(&gw, &gd);
- SetGWorld(theDocument->theWindow,nil);
-
- // Create filename for image
- outSpec = theDocument->theFileSpec;
- for(i = 1; i <= fName[0];i++)
- outSpec.name[i+outSpec.name[0]] = fName[i];
- outSpec.name[0] += fName[0];
-
- // Set up buffers and regions
- err = NewGWorld(&largeGW, 32, &largeRect, nil, nil, useTempMem );
- if(err)
- return ;
- LockPixels(largeGW->portPixMap);
- SetGWorld(largeGW,nil);
- EraseRect( &largeRect);
- sourceRect = destRect = largeRect;
- sourceRect.left = 256-factor/2.0;
- sourceRect.right = sourceRect.left + (short)factor;
- destRect.left = 0;
- destRect.right = (short)factor;
-
- counter = 0;
-
- for(zAngle = 360.0;zAngle >0.0; zAngle -= 360.0/(2496.0/factor)) {
- if (Button())
- break;
-
- // Rotate camera for next shot
- MyRotateCameraY(theDocument, -2*kQ3Pi/(2496.0/factor));
-
- // Render image
- SetGWorld(theDocument->theWindow,nil);
- MyDrawOffScreen(theDocument);
- MyDrawOnScreen(theDocument);
-
- // Copy image to destination (paste in next slit)
- SetGWorld(largeGW,nil);
- LockPixels(theDocument->drawContextOffscreen->portPixMap);
- CopyBits((BitMap*)&theDocument->drawContextOffscreen->portPixMap,
- (BitMap*)&largeGW->portPixMap,
- &sourceRect,
- &destRect,
- srcCopy,NULL);
- UnlockPixels(theDocument->drawContextOffscreen->portPixMap);
- destRect.left = destRect.left + (short)factor;
- destRect.right = destRect.right + (short)factor;
- }
-
- // Copy final image and save.
- SetGWorld(largeGW,nil);
- thePict = OpenPicture(&largeGW->portRect);
- CopyBits((BitMap*)&largeGW->portPixMap,
- (BitMap*)&largeGW->portPixMap,
- &largeGW->portRect,
- &largeGW->portRect,
- srcCopy,NULL);
- ClosePicture();
- UnlockPixels(largeGW->portPixMap);
- DisposeGWorld(largeGW);
- MySavePICT(thePict,&outSpec);
-
- // Clean up.
- KillPicture(thePict);
- SetGWorld(theDocument->theWindow,nil);
- MyDrawOffScreen(theDocument);
- MyDrawOnScreen(theDocument);
- SetGWorld(gw,gd);
- }
-
- OSErr MySavePICT(PicHandle picture, FSSpec *theSpec)
- {
- long bytes;
- OSErr err;
- short fRefNum;
-
- FSpDelete (theSpec);
- err = FSpCreate (theSpec, '3DVR', 'PICT', smCurrentScript);
-
- if(err)
- return err;
-
- err = FSpOpenDF (theSpec, fsRdWrPerm, &fRefNum);
- if(err)
- return err;
-
- bytes = 512;
- FSWrite(fRefNum,&bytes,(Ptr)NULL);
- HLock((Handle)picture);
- bytes = GetHandleSize((Handle)picture);
- FSWrite(fRefNum,&bytes,(Ptr)(*picture));
- HUnlock((Handle)picture);
- FSClose(fRefNum);
- FlushVol(theSpec->name,theSpec->vRefNum);
-
- return err;
- }
-
-